package com.heny.demo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heny.demo.common.CommonErrorCode;
import com.heny.demo.common.CommonException;
import com.heny.demo.common.CommonResult;
import com.heny.demo.entity.TurnPoint;
import com.heny.demo.entity.TurnPointVO;
import com.heny.demo.mapper.TurnPointMapper;
import com.heny.demo.service.TurnPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@RestController
public class TurnPointController {

    @Autowired
    private TurnPointService turnPointService;


    @PostMapping("/upload")
    public CommonResult<Boolean> uploadTurnPoint(MultipartFile file) {
        CommonResult<Boolean> result = new CommonResult<>();
        try{
            boolean data = turnPointService.uploadTurnPoint(file);
            result.setSuccess(true);
            result.setData(data);
        }catch (CommonException e){
            result = CommonResult.ofFailure(e.getErrorCode().getCode(),e.getMessage());
        }catch (Exception e){
            result = CommonResult.ofFailure(CommonErrorCode.SYSTEM_ERROR.getCode(), e.getMessage());
        }

        return result;
    }

    @GetMapping("/getById")
    public CommonResult<TurnPointVO> getById(Integer id){
        return CommonResult.ofSuccess(new TurnPointVO(turnPointService.getById(id)));
    }


}